const express=require('express')
const router= express.Router();
const db=require('../../utils/db')

router.get('/xuanran',function(req,res){
  let mysql=`SELECT check_id,menu_file.menu_id as lb,user.user_id as zd,t1.user_id as sh,menu_category as check_type,user.user_name as check_preparer,t1.user_name as check_auditor,check_atime,check_mtime,check_note,check_time,shenhe FROM stock_check
  JOIN menu_file ON menu_file.menu_id =stock_check.check_type 
  JOIN USER ON user.user_id =stock_check.check_preparer 
  JOIN USER AS t1 ON t1.user_id =stock_check.check_auditor
  ORDER BY shenhe ASC  `
  db(mysql,null,function(err,data){
    if(err){
        return res.json({
            code: 500,
            msg: '查询菜品失败，请稍后重试'
        })
    }
    res.json({
        code: 200,
        msg: '查询菜品成功',
        data: data
    })
})
})

//编辑
router.post('/bianji',function(req,res){
    console.log(req.body);
        let mysql=`UPDATE stock_check SET check_type =${req.body.lb},check_preparer =${req.body.zd},check_auditor =${req.body.sh}, check_atime =${req.body. check_atime},check_mtime =${req.body.check_mtime},check_note =${req.body.check_note},check_time =${req.body.check_time},shenhe =${req.body.shenhe} WHERE check_id =${req.body.check_id}`
        db(mysql,null,function(err,data){
          if(err){
              return res.json({
                  code: 500,
                  msg: '修改失败，请稍后重试'
              })
          }
          res.json({
              code: 200,
              msg: '修改成功'
          })
      })
      })


      //增加
  router.post('/xinzen',function(req,res){
    console.log(req.body);
     let mysql=`INSERT INTO stock_check (check_id,check_type,check_preparer,check_auditor,check_mtime,check_note,shenhe) VALUES (${parseInt(req.body.check_id)},${parseInt(req.body.check_type)},${parseInt(req.body.check_preparer)},${parseInt(req.body.check_auditor)},'${req.body.check_mtime}','${req.body.check_note}',0)`
   
    db(mysql,null,function(err,data){
      if(err){
          return res.json({
              code: 500,
              msg: '增加失败，请稍后重试'
          })
      }
      res.json({
          code: 200,
          msg: '增加成功'
      })
  })
  })
module.exports = router